package gsw.tool.eventbus.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;

import gsw.tool.eventbus.core.Hermes;
import gsw.tool.eventbus.response.InstanceResponceMake;
import gsw.tool.eventbus.response.ObjectResponceMake;
import gsw.tool.eventbus.response.Response;
import gsw.tool.eventbus.response.ResponceMake;
import gsw.tool.eventbus.eventbus.EventBusService;
import gsw.tool.eventbus.request.Request;

/**
 * 远程服务，用于跨进程通信
 */
public class HermesService extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }

    //跨进程通信的Binder对象
    private EventBusService.Stub mBinder = new EventBusService.Stub() {
        @Override
        public Response send(Request request) throws RemoteException {
            //对请求参数进行处理  生成Responce结果返回
            ResponceMake responceMake = null;
            switch (request.getType()) {
                case Hermes.TYPE_GET://获取单例
                    responceMake = new InstanceResponceMake();
                    break;
                case Hermes.TYPE_NEW://普通对象
                    responceMake = new ObjectResponceMake();
                    break;
            }
            return responceMake.makeResponce(request);
        }
    };

    public static class HermesService0 extends HermesService {
    }

    public static class HermesService1 extends HermesService {
    }

    public static class HermesService2 extends HermesService {
    }

    public static class HermesService3 extends HermesService {
    }

    public static class HermesService4 extends HermesService {
    }

    public static class HermesService5 extends HermesService {
    }

    public static class HermesService6 extends HermesService {
    }

    public static class HermesService7 extends HermesService {
    }

    public static class HermesService8 extends HermesService {
    }

    public static class HermesService9 extends HermesService {
    }
}
